package top.haichi.webpaper.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.cors.CorsConfiguration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Slf4j
@Configuration
public class GlobalCorsConfig implements WebMvcConfigurer {

    @Value("${address.allow}")
    private String allowedOrigin;

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        log.info("allowOrigin:"+allowedOrigin);
        registry.addMapping("/**")
                .allowedOrigins(allowedOrigin)
                .allowedMethods("GET","POST");
    }
}

